package com.example.demo.controller;

import com.example.demo.common.R;
import com.example.demo.entity.Company;
import com.example.demo.entity.User;
import com.example.demo.service.CompanyService;
import io.swagger.annotations.Api;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "公司管理")
@Log4j2
@RequestMapping("company")
@RestController
public class CompanyController {
    @Autowired
    CompanyService companyService;

    @GetMapping("list")
    public R list(
            @RequestParam(defaultValue = "1") int current,
            @RequestParam(defaultValue = "10") int size
    ){
        return R.ok(companyService.list(current, size));
    }
    @GetMapping("detail")
    public R detail(long id){
        return R.ok(companyService.getById(id));
    }

    @PostMapping("save")
    public R save(Company company){
        return R.okFail(companyService.saveOrUpdate(company));
    }
    @GetMapping("remove")
    public R remove(long id){
        return R.okFail(companyService.removeById(id));
    }
}
